% Copyright (C) 2014-19 Benjamin Born and Johannes Pfeifer 
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% For a copy of the licencse,
% see <http://www.gnu.org/licenses/>.

n_obs = 0;
for country_iter=1:size(country_indices_non_NaN)
    country_name=country_indicator_names_mapping{data_array_for_regression_stacked_by_variable(1,country_indices_non_NaN(country_iter),pos.country_ident)};
    stacked_data=squeeze(cat(3,dependent_variable_for_run(:,country_iter),data_array_for_regression_for_run(:,country_iter,:)));
    first_obs_index=find(~any(isnan(stacked_data),2),1,'first');
    last_obs_index=find(~any(isnan(stacked_data),2),1,'last');
    NaN_obs=sum(any(isnan(stacked_data(first_obs_index:last_obs_index,:)),2));
    first_obs=data_array_for_regression_stacked_by_variable(time_indices_non_NaN(first_obs_index),pos.timeline);
    last_obs=data_array_for_regression_stacked_by_variable(time_indices_non_NaN(last_obs_index),pos.timeline);
    n_obs = n_obs + (last_obs_index-first_obs_index+1-NaN_obs)
end

n_countries = size(country_indices_non_NaN,1);